(function($){ 
	$.fn.popeScroll = function(options){ 
		var defaults = { 
			height:345,
			width:7,
			imgpath:"../../",
			right:18,
			offset_top:200,
			top:25,
			mousewheelBox:"",
			mousewheelnum:0,
			nobar:false
			
		};
		var options = $.extend(defaults, options); 
		var id = $(this).attr("id");
		var height = options.height;
		var width = options.width;
		var imgpath = options.imgpath;
		var right = options.right;
		var offset_top = options.offset_top;
		var top = options.top;
		var mousewheelBox = options.mousewheelBox;
		var mousewheelnum = options.mousewheelnum;
		var nobar = options.nobar;
		
		
		var div = '<div id="scroll_'+id+'" class="popeScroll" style="position: fixed;display:none;">'+
		'<div style="margin:0 auto;position: fixed;top:'+top+'%;right:'+right+'px;"><img src="'+imgpath+'image/slider3.png" style="height:'+height+'px;width:7px;"/></div>'+
		'<div id="scroll_iconbox_'+id+'" style="margin:0 auto;position: fixed;top:'+top+'%;right:'+(right-2)+'px;height:'+height+'px;"><img id="scroll_icon_'+id+'" src="'+imgpath+'image/slider1.png" style="width:11px;height:11px;cursor:pointer;"/></div></div>';
		
		$("#scroll_"+id).remove();
		
		$("body").append(div);
		
		$("#scroll_icon_"+id).draggable({
			axis: "y",
			containment:"#scroll_iconbox_"+id,
			drag:function(){
				scroll(this,id);
			},
			stop:function(){
				scroll(this,id);
			}
		});
		if(mousewheelBox==""){
			mousewheelBox = id;
		}
		
		
		
		
		$('#'+mousewheelBox).mousewheel(function(event, delta, deltaX, deltaY) {
			if(mousewheelnum == 0){
				var tarH = parseInt($("#"+id).css("height"));
				if(tarH != 0){
					mousewheelnum = parseInt((height/tarH)*100);
					
				}
				
			}
			
			
			if (delta > 0){
				var top = $("#scroll_icon_"+id).css("top");
				if(top=="auto"){
					top="0px";
				}
				var topN = parseInt(top.replace("px",""))-mousewheelnum;
				if(topN<0){
					topN=0;
				}
				$("#scroll_icon_"+id).css("top",topN+"px");
				scroll($("#scroll_icon_"+id)[0],id);
			}else if (delta < 0){
				var top = $("#scroll_icon_"+id).css("top");
				if(top=="auto"){
					top="0px";
				}
				var topN = parseInt(top.replace("px",""))+mousewheelnum;
				if(topN>height){
					topN = height-12;
				}
				$("#scroll_icon_"+id).css("top",topN+"px");
				scroll($("#scroll_icon_"+id)[0],id);
				
			}else{
			
			}
			return false; // prevent default
		});
		if(!nobar){
			$("#scroll_"+id).show();
		}else{
			$("#scroll_"+id).addClass("transparent_0");
			$("#scroll_"+id).show();
		}
		
		

		function scroll(obj,target){
			var posX = $(obj).position().top;
			
			var conH = parseInt($("#"+target).css("height"));
			$("#"+target).css("margin-top",0-posX*((conH+offset_top)/height));
		}
		
		
		
		this.each(function(){ 

			
		}); 
	};

})(jQuery); 